package com.ftg.learn.day07;

/**
 * 线程处理方式01
 *
 * @author 布衣
 */
public class Sync01 {

    //extends Thread
    //implements Runnable
    //implements Callable

    //线程池 : ----》 异步  同步

    static int num = 1000;

    //锁  ： synchronized 同步锁

    Object o= new Object();
    Object o1= new Object();

    public  void add(){
        synchronized (o){
            num++;
        }
    }

    public synchronized void mult(){
        synchronized (o1){
            num--;
        }
    }
    public static void main(String[] args) {

        //工作线程01
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println("===>1111==>"+Sync01.num--);
                }
            }
        }).start();


        //启动工作线程01

        //工作线程02
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println("===>222==>"+Sync01.num--);
                }
            }
        });
        //启动工作线程02
        t1.start();
        System.out.println("==yyy=>" + Sync01.num);

        String s1 = new String("abc");
        String s2 = s1.intern();

        System.out.println(s1 == s2);
    }

}
